package com.Prot2.Logger;

import com.Prot2.Globals;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;



public class AccelerationWorker {
	
	private SensorManager mSensorManager;
	private float aX,aY,aZ;
	
	public AccelerationWorker(Context c){
    	mSensorManager= (SensorManager) c.getSystemService(Context.SENSOR_SERVICE);
    	mSensorManager.registerListener(mAccelerationListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),Globals.samplingRate*1000);

	}
	
	private SensorEventListener mAccelerationListener = new SensorEventListener() {

		@Override
		public void onAccuracyChanged(Sensor arg0, int arg1) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onSensorChanged(SensorEvent event) {
			if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
				aX = event.values[0];
	        	aY = event.values[1];
	        	aZ = event.values[2];
			}
		}
		
	};
	
	public float getXAcc(){
		return aX;
	}
	public float getYAcc(){
		return aY;
	}
	public float getZAcc(){
		return aZ;
	}
	public String getRead(String DELIMITER){
		return ""+aX+DELIMITER+aY+DELIMITER+aZ;
	}
	
	public void stop(){
		mSensorManager.unregisterListener(mAccelerationListener);
	}
	
}
